<template>
  <div>
    <el-dialog
      :title="form.title"
      width="800px"
      class="icon-dialog"
      :visible.sync="show"
      :before-close="closeForm"
      append-to-body
      @open="open"
    >
      <el-form
        ref="form"
        :size="size"
        :model="form"
        :rules="rules"
        :label-width="$store.getters.device !== 'mobile'?'16%':'90px'"
      >
      <table
        class="table table-bordered"
        align="center"
        width="100%"
        style="word-break:break-all; margin-bottom:50px;  font-size:13px;"
      >
        <tbody>
          <tr>
            <td class="title" width="100">名称：</td>
            <td>
              {{ form.name }}
            </td>
          </tr>
          <tr>
            <td class="title" width="100">备注：</td>
            <td>
              {{ form.remark }}
            </td>
          </tr>
          <tr>
            <td class="title" width="100">申请时间：</td>
            <td>
              {{ form.create_time }}
            </td>
          </tr>
          <tr>
            <td class="title" width="100">审核状态：</td>
            <td>
              {{ form.status == 1?'已批准':form.status == 2?'已驳回': '待审核' }}
            </td>
          </tr>
        </tbody>
      </table>

      <el-table
        ref="multipleTable"
        v-loading="loading"
        :row-class-name="rowClass"
        :tree-props="{children: 'children'}"
        :default-expand-all="expand"
        row-key="id"
        :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
        :border="false"
        :stripe="true"
        class="eltable"
        :data="list"
        style="width: 100%"
        @selection-change="selection"
      >
        <el-table-column
          align="center"
          type=""
          property="gid"
          label="商品id"
          show-overflow-tooltip
          width="70"
        />
        <el-table-column
          align="left"
          property="name"
          label="名称"
          show-overflow-tooltip
          width=""
        />
        <el-table-column
          align="left"
          property="stock"
          label="数量"
          show-overflow-tooltip
          width=""
        />

      </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="form.status == 0">
        <el-button :loading="loading" type="primary" @click="submit(1)">
          <span v-if="!loading">审核通过</span>
          <span v-else>提 交 中...</span>
        </el-button>
        <el-button :loading="loading" type="danger" @click="submit(2)">
          <span v-if="!loading">审核驳回</span>
          <span v-else>提 交 中...</span>
        </el-button>
        <el-button @click="closeForm">取 消</el-button>
      </div>
      <div slot="footer" class="dialog-footer" v-else>
        <el-button @click="closeForm">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import ImagesUpload from '@/components/common/ImagesUpload.vue'
export default {
  name: 'Servicecategoryupdate',
  components: {
    ImagesUpload
  },
  props: {
    show: {
      type: Boolean,
      default: false
    },
    opentype: {
      type: String,
      default: 'add'
    },
    size: {
      type: String,
      default: 'small'
    },
    info: {
      type: Object
    }
  },
  data() {
    return {
      dialogtitle: '',
      servicedeliverymodearray:[],
      form: {
        title: '',
        ptype: 2,
        status: 1
      },
      list:[],
      pids: [],
      ptypearray: [],
      loading: false,
      rules: {
        name: [{
          required: true,
          message: '名称不能为空',
          trigger: 'blur'
        }]
      }
    }
  },
  methods: {
    open() {
      if (this.opentype == 'update') {
        this.dialogtitle = '修改'
        this.form = this.info
        this.list=this.info.list
        if (this.info.pid == '0') {
          this.$delete(this.info, 'pid')
        }
      } else {
        this.dialogtitle = '添加'
        this.form = {
          ptype: 2,
          deliverymode: 1,
          status: 1
        }
      }
    },
    submit(status) {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.loading = true;
          this.form.status = status;
          this.$api.post('/stockorder/update', {id: this.form}).then(res => {
            this.$message({
              message: res.msg,
              type: 'success'
            })
            this.$emit('refesh_list')
            this.closeForm()
          }).catch(() => {
            this.loading = false
          })
        }
      })
    },
    normalizer(data) {
      if (data.children && !data.children.length) {
        delete data.children
      }
      return {
        id: data.val,
        label: data.key,
        children: data.children
      }
    },
    closeForm() {
      this.$emit('update:show', false)
      this.loading = false
      if (this.$refs['form'] !== undefined) {
        this.$refs['form'].resetFields()
      }
    }
  }
}
</script>
